<template>
  <app-navbar></app-navbar>
  <div class="home-layout">
    <side-bar v-if="isLoggedIn" />
    <div class="home-view" :style="{ marginLeft: isLoggedIn ? '180px' : '0' }">
      <!-- 搜索框区域 -->
      <div class="game-list-header" style="max-width:1300px;width:100vw;margin:80px auto 0 auto;">
        <input v-model="searchKeyword" @keyup.enter="fetchGames(1)" placeholder="搜索游戏名..." class="game-search-input" />
        <button @click="fetchGames(1)" class="game-search-btn">搜索</button>
      </div>
      <!-- 轮播图区域 -->
      <div class="banner-carousel" v-if="banners.length">
        <div
          v-for="(videoUrl, idx) in banners"
          :key="videoUrl"
          class="banner-slide"
          :class="{ active: idx === currentBanner }"
        >
          <video
            v-if="videoUrl"
            :src="videoUrl"
            class="banner-video"
            autoplay
            muted
            loop
            playsinline
            style="width:100%;height:100%;object-fit:cover;position:absolute;top:0;left:0;z-index:2;"
          ></video>
          <div class="banner-overlay"></div>
        </div>
        <button class="carousel-btn left" @click="prevBanner">
          <svg width="28" height="28" viewBox="0 0 28 28"><polyline points="18,6 10,14 18,22" fill="none" stroke="#00fff0" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
        </button>
        <button class="carousel-btn right" @click="nextBanner">
          <svg width="28" height="28" viewBox="0 0 28 28"><polyline points="10,6 18,14 10,22" fill="none" stroke="#00fff0" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
        </button>
        <div class="carousel-dots">
          <span
            v-for="(videoUrl, idx) in banners"
            :key="'dot'+idx"
            :class="{ dot: true, active: idx === currentBanner }"
            @click="goBanner(idx)"
          ></span>
        </div>
      </div>
      <div class="divider"></div>
      <!-- 游戏分页区 -->
      <div class="game-paginated-list">
        <div v-if="loading" class="game-loading">加载中...</div>
        <div v-else class="game-list">
          <div v-for="game in gamesList" :key="game.id" class="game-card-adv" @click="showDetail(game.id)" style="cursor:pointer;">
            <div class="game-img-wrap">
              <img v-if="game.trailerPicture" :src="game.trailerPicture" :alt="game.title" class="game-img" />
              <div v-else class="game-img-placeholder">无图片</div>
              <span class="game-status" :class="{'status-onshelf': game.status==='1', 'status-pending': game.status==='0'}">
                {{ game.status==='1' ? '已上架' : '待上架' }}
              </span>
            </div>
            <div class="game-info-adv">
              <h3>{{ game.title }}</h3>
              <p class="game-desc">{{ game.description || '暂无描述' }}</p>
              <div class="game-meta">
                <span>类型：{{ game.genre }}</span>
                <span>平台：{{ game.platforms }}</span>
              </div>
              <div class="game-pricing">
                <span class="game-price" :class="{'strike': game.discountPrice && game.discountPrice !== game.price}">￥{{ game.price }}</span>
                <span v-if="game.discountPrice && game.discountPrice !== game.price" class="game-discount">￥{{ game.discountPrice }}</span>
              </div>
              <div class="game-rating" v-if="game.rating != null">
                <span class="star-rating">
                  <span v-for="(type, idx) in getStars(game.rating)" :key="idx">
                    <svg v-if="type==='full'" class="star" viewBox="0 0 20 20"><polygon points="10,1 12.59,7.36 19.51,7.64 14,12.14 15.82,19.02 10,15.27 4.18,19.02 6,12.14 0.49,7.64 7.41,7.36"/></svg>
                    <svg v-else-if="type==='half'" class="star" viewBox="0 0 20 20"><defs><linearGradient id="half"><stop offset="50%" stop-color="#00fff0"/><stop offset="50%" stop-color="#232946"/></linearGradient></defs><polygon fill="url(#half)" points="10,1 12.59,7.36 19.51,7.64 14,12.14 15.82,19.02 10,15.27 4.18,19.02 6,12.14 0.49,7.64 7.41,7.36"/></svg>
                    <svg v-else class="star empty" viewBox="0 0 20 20"><polygon points="10,1 12.59,7.36 19.51,7.64 14,12.14 15.82,19.02 10,15.27 4.18,19.02 6,12.14 0.49,7.64 7.41,7.36"/></svg>
                  </span>
                </span>
                <span class="rating-num">{{ (game.rating/2).toFixed(1) }}</span>
              </div>
            </div>
          </div>
          <div v-if="gamesList.length === 0 && !loading" class="game-empty">暂无数据</div>
        </div>
        <div class="game-pagination">
          <button @click="prevPage" :disabled="page<=1">上一页</button>
          <span>第 {{ page }} / {{ totalPages }} 页</span>
          <button @click="nextPage" :disabled="page>=totalPages">下一页</button>
        </div>
      </div>
    </div>
  </div>

  <!-- 详情弹窗 -->
  <transition name="fade">
    <div v-if="detailGame" class="game-detail-modal" @click.self="closeDetail">
      <div class="modal-content scrollable-modal pro-modal modal-content-topimg">
        <div v-if="detailGame.trailerPicture" class="modal-img-inner-top-bar">
          <img :src="detailGame.trailerPicture" class="modal-img-inner-top" alt="游戏图片" />
        </div>
        <div class="modal-info-card">
          <h2 class="pro-title">{{ detailGame.title }}</h2>
          <div class="pro-price-rating">
            <span class="pro-price">￥{{ detailGame.price }}</span>
            <span v-if="detailGame.discountPrice && detailGame.discountPrice !== detailGame.price" class="pro-discount">￥{{ detailGame.discountPrice }}</span>
            <span class="star-rating pro-star">
              <span v-for="n in 5" :key="n">
                <svg v-if="n <= Math.round(detailGame.rating/2)" class="star filled" viewBox="0 0 20 20"><polygon points="10,1 12.59,7.36 19.51,7.64 14,12.14 15.82,19.02 10,15.27 4.18,19.02 6,12.14 0.49,7.64 7.41,7.36"/></svg>
                <svg v-else class="star empty" viewBox="0 0 20 20"><polygon points="10,1 12.59,7.36 19.51,7.64 14,12.14 15.82,19.02 10,15.27 4.18,19.02 6,12.14 0.49,7.64 7.41,7.36"/></svg>
              </span>
              <span class="rating-num">{{ (detailGame.rating/2).toFixed(1) }}</span>
            </span>
          </div>
          <div class="pro-meta-row">
            <span>类型：{{ detailGame.genre }}</span>
            <span>平台：{{ detailGame.platforms }}</span>
          </div>
          <div class="pro-config-row">
            <span>推荐配置：</span>
            <span>CPU: {{ detailGame.configCpu }}</span>
            <span>GPU: {{ detailGame.configGpu }}</span>
            <span>内存: {{ detailGame.configRam }}GB</span>
            <span>存储: {{ detailGame.configStorage }}</span>
          </div>
          <div class="pro-devices">支持设备：{{ detailGame.gameSupportedDevices }}</div>
          <div class="pro-desc">{{ detailGame.description }}</div>
        </div>
        <div class="divider-line"></div>
        <div class="comment-section pro-comment">
          <h3>评论区</h3>
          <div class="comment-list">
            <template v-if="commentList.length === 0">
              <div class="comment-placeholder">暂无评论</div>
            </template>
            <template v-else>
              <div v-for="(item, idx) in commentList" :key="idx" class="comment-item">
                <div class="comment-header">
                  <span class="comment-nick">{{ item.nickName }}</span>
                  <span class="comment-time">{{ formatCommentTime(item.commentTime) }}</span>
                </div>
                <div class="comment-content">{{ item.commentContent }}</div>
              </div>
              <div v-if="!allCommentsLoaded" class="comment-more-row">
                <button class="comment-more-btn" @click="loadMoreComments">显示更多</button>
              </div>
            </template>
          </div>
          <div class="comment-input-bar">
            <input v-model="newComment" class="comment-input" placeholder="说点什么..." />
            <button class="comment-submit-btn" @click="submitComment">发布评论</button>
          </div>
        </div>
        <div class="modal-btn-row">
          <button class="close-btn" @click="closeDetail">关闭</button>
          <button class="buy-btn" @click="buyGame">购买</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script setup>
import { ref, onMounted, onUnmounted, computed, watch } from 'vue'
import AppNavbar from '@/components/AppNavbar.vue'
import SideBar from '@/components/SideBar.vue'
import axios from 'axios'
import { webSocketService } from '@/websocket'
// 存储游戏评论的Map
const gameComments = new Map();
// 存储取消订阅的函数
let unsubscribeFunctions = new Map();

const isLoggedIn = ref(localStorage.getItem('isLoggedIn') === 'true')

const banners = ref([])
const currentBanner = ref(0)
let timer = null

const nextBanner = () => {
  currentBanner.value = (currentBanner.value + 1) % banners.value.length
}
const prevBanner = () => {
  currentBanner.value = (currentBanner.value - 1 + banners.value.length) % banners.value.length
}
const goBanner = idx => {
  currentBanner.value = idx
}

onMounted(() => {
  timer = setInterval(nextBanner, 4000)
  fetchGames(1)
  // 连接WebSocket
  webSocketService.connect('ws://localhost:8080/push');
  console.log('HomeView: WebSocket连接已建立');
})
onUnmounted(() => {
  clearInterval(timer)
  // 断开WebSocket连接
  webSocketService.disconnect();
  console.log('HomeView: WebSocket连接已断开');
  // 清除所有订阅
  unsubscribeFunctions.forEach(unsubscribe => unsubscribe());
  unsubscribeFunctions.clear();
})

const gamesList = ref([])
const page = ref(1)
const pageSize = ref(9)
const total = ref(0)
const searchKeyword = ref('')
const loading = ref(false)
const totalPages = computed(() => Math.ceil(total.value / pageSize.value))

const fetchGames = async (toPage = page.value) => {
  loading.value = true
  try {
    const params = {
      page: String(toPage),
      pageSize: String(pageSize.value)
    }
    if (searchKeyword.value) params.title = searchKeyword.value
    const res = await axios.get('http://localhost:8080/game/list', { params })
    if (res.data && res.data.data) {
      gamesList.value = res.data.data.records || []
      total.value = res.data.data.total || 0
      page.value = toPage
      // 动态设置轮播图
      banners.value = gamesList.value.slice(0, 3).map(g => g.trailerVideo).filter(Boolean)
      currentBanner.value = 0
    }
  } catch (e) {
    gamesList.value = []
    total.value = 0
    banners.value = []
  } finally {
    loading.value = false
  }
}
const prevPage = () => {
  if (page.value > 1) fetchGames(page.value - 1)
}
const nextPage = () => {
  if (page.value < totalPages.value) fetchGames(page.value + 1)
}

// 星星评分渲染函数
function getStars(rating) {
  if (rating == null) return [];
  const stars = [];
  const fiveStar = Math.round((rating / 10) * 5 * 2) / 2; // 10分制转5星，支持半星
  for (let i = 1; i <= 5; i++) {
    if (fiveStar >= i) {
      stars.push('full');
    } else if (fiveStar >= i - 0.5) {
      stars.push('half');
    } else {
      stars.push('empty');
    }
  }
  return stars;
}

const detailGame = ref(null)
const showDetail = async (gameId) => {
  // 确保gameId是字符串类型
  const id = String(gameId);
  console.log(`HomeView: 显示游戏 ${id} 详情`);
  try {
    // 直接用axios原生实例，不用全局带token的实例
    const axiosRaw = (await import('axios')).default;
    const res = await axiosRaw.get(`http://localhost:8080/game/getGameDetails/${gameId}`)
    if(res.data && res.data.code === 200) {
      detailGame.value = res.data.data
      // 加载评论
      fetchComments(true);
      // 初始化该游戏的评论数组
      if (!gameComments.has(id)) {
        gameComments.set(id, []);
        console.log(`HomeView: 初始化游戏 ${id} 评论数组`);
      }
      // 订阅该游戏的评论
      if (!unsubscribeFunctions.has(id)) {
        const unsubscribe = webSocketService.subscribe(id, (comment) => {
          console.log(`HomeView: 收到游戏 ${id} 的新评论:`, comment);
          // 将新评论添加到评论列表末尾
          if (gameComments.has(id)) {
            const comments = gameComments.get(id);
            comments.push(comment); // 添加到数组末尾
            // 如果当前查看的是这个游戏的详情，则更新评论列表
            if (detailGame.value && String(detailGame.value.id) === id) {
              // 保持评论列表顺序，新评论在最下面
              commentList.value = [...comments];
              console.log(`HomeView: 更新游戏 ${id} 的评论列表，当前评论数: ${comments.length}`);
            }
          }
        });
        unsubscribeFunctions.set(id, unsubscribe);
        console.log(`HomeView: 订阅游戏 ${id} 的评论成功`);
      }
    } else {
      alert('获取详情失败')
    }
  } catch(e) {
    alert('网络错误或服务器异常')
  }
}
const closeDetail = () => {
  detailGame.value = null
}
const newComment = ref("")
function showAppNavbarLogin() {
  window.dispatchEvent(new Event('show-login-dialog'))
  closeDetail()
}
function submitComment() {
  if (!isLoggedIn.value) {
    showAppNavbarLogin()
    return
  }
  // 这里预留评论提交逻辑
  alert("评论功能待接入后端接口！");
  newComment.value = ""
}
function buyGame() {
  if (!isLoggedIn.value) {
    showAppNavbarLogin()
    return
  }
  alert("购买功能待接入后端接口！");
}

const commentList = ref([])
const commentPage = ref(1)
const commentPageSize = 10
const allCommentsLoaded = ref(false)

async function fetchComments(reset = false) {
  if (!detailGame.value) return;
  const id = String(detailGame.value.id);
  if (reset) {
    commentPage.value = 1;
    commentList.value = [];
    allCommentsLoaded.value = false;
  }
  // 用axios原生实例，不带token
  const axiosRaw = (await import('axios')).default;
  const res = await axiosRaw.get('http://localhost:8080/comment/getComment', {
    params: {
      gameId: detailGame.value.id,
      page: commentPage.value,
      pageSize: commentPageSize
    }
  })
  if (res.data && Array.isArray(res.data.data)) {
    if (res.data.data.length < commentPageSize) {
      allCommentsLoaded.value = true;
    }
    // 首先处理后端数据
    if (commentPage.value === 1) {
      commentList.value = res.data.data;
    } else {
      commentList.value = commentList.value.concat(res.data.data);
    }
    // 然后合并WebSocket推送的评论（如果有）
    if (gameComments.has(id)) {
      const wsComments = gameComments.get(id);
      // 过滤掉已经在commentList中的评论
      const newComments = wsComments.filter(wsComment => 
        !commentList.value.some(c => c.id === wsComment.id)
      );
      // 添加新评论到commentList
      commentList.value = [...commentList.value, ...newComments];
    }
    // 按时间排序，最新的在最后
    commentList.value.sort((a, b) => new Date(a.createTime) - new Date(b.createTime));
    // 更新gameComments
    gameComments.set(id, [...commentList.value]);
  } else {
    allCommentsLoaded.value = true;
  }
  // 确保评论列表被正确更新
  console.log(`HomeView: 加载评论完成，当前评论数: ${commentList.value.length}`);
}
function loadMoreComments() {
  commentPage.value++;
  fetchComments();
}
function formatCommentTime(time) {
  if (!time) return '';
  const d = new Date(time);
  return d.toLocaleString();
}
// 在弹窗打开时加载评论
watch(detailGame, (val) => {
  if (val && val.id) {
    fetchComments(true);
  }
})
</script>

<style scoped>
.home-layout {
  display: flex;
  flex-direction: row;
  width: 100vw;
  min-height: 100vh;
}

.home-view {
  min-height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #181a20 60%, #232946 100%);
  color: #b0b3b8;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  transition: margin-left 0.3s cubic-bezier(.4,0,.2,1);
}

.banner-carousel {
  position: relative;
  width: 100vw;
  max-width: 1300px;
  margin: 56px auto 48px auto;
  overflow: hidden;
  border-radius: 24px;
  box-shadow: 0 8px 40px 0 rgba(0,0,0,0.55), 0 0 24px #00fff055;
  border: 2.5px solid #232946;
  background: #181a20;
  min-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.banner-slide {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.8s cubic-bezier(.4,0,.2,1);
  z-index: 1;
  filter: brightness(1.12) contrast(1.12);
}
.banner-slide.active {
  opacity: 1;
  z-index: 2;
}
.banner-overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, rgba(24,26,32,0.18) 0%, rgba(24,26,32,0.32) 60%, rgba(35,41,70,0.55) 100%);
  box-shadow: 0 0 80px 0 #00fff022 inset;
  z-index: 3;
  pointer-events: none;
}
.carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, rgba(0,255,240,0.18) 0%, rgba(35,41,70,0.85) 100%);
  border: 2.5px solid #00fff0;
  color: #00fff0;
  border-radius: 50%;
  cursor: pointer;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px #00fff055, 0 2px 8px #23294699;
  transition: background 0.22s, box-shadow 0.22s, border 0.22s, color 0.22s;
  outline: none;
  opacity: 0.92;
  padding: 0;
}
.carousel-btn.left { left: 28px; }
.carousel-btn.right { right: 28px; }
.carousel-btn:hover {
  background: linear-gradient(135deg, #00fff0 0%, #232946 100%);
  color: #181a20;
  box-shadow: 0 0 32px #00fff0, 0 2px 12px #232946cc;
  border: 2.5px solid #00fff0;
  opacity: 1;
}
.carousel-btn svg {
  display: block;
  width: 28px;
  height: 28px;
  pointer-events: none;
}
.carousel-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  border: 2.5px solid #444;
}
.carousel-dots {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 5;
}
.dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #232946;
  opacity: 0.5;
  cursor: pointer;
  transition: background 0.3s, opacity 0.3s, box-shadow 0.3s;
  box-shadow: 0 0 0 #00fff0;
}
.dot.active {
  background: #00fff0;
  opacity: 1;
  box-shadow: 0 0 12px #00fff0;
}

.divider {
  width: 100vw;
  max-width: 1300px;
  height: 2px;
  margin: 48px 0 0 0;
  background: linear-gradient(90deg, transparent 0%, #00fff0 50%, transparent 100%);
  opacity: 0.18;
  border-radius: 1px;
}

.game-paginated-list {
  max-width: 1300px;
  width: 100vw;
  margin: 64px auto 0 auto;
  background: rgba(24,26,32,0.92);
  border-radius: 20px;
  box-shadow: 0 4px 32px 0 #00fff022, 0 0 0 2px #232946;
  border: 1.5px solid #232946;
  backdrop-filter: blur(2.5px);
  padding: 0 0 48px 0;
}

.game-list-header {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.game-search-input {
  flex: 1;
  padding: 12px;
  border: 2px solid #232946;
  border-radius: 8px;
  background: #181a20;
  color: #b0b3b8;
}

.game-search-btn {
  padding: 12px 24px;
  border: 2px solid #00fff0;
  border-radius: 8px;
  background: #00fff0;
  color: #181a20;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.game-search-btn:hover {
  background: rgba(0,255,240,0.22);
}

.game-loading {
  text-align: center;
  margin: 24px 0;
  color: #00fff0;
}

.game-list {
  display: flex;
  gap: 40px 48px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-card-adv {
  background: linear-gradient(135deg, rgba(35,41,70,0.92) 60%, rgba(0,255,240,0.08) 100%);
  border-radius: 18px;
  box-shadow: 0 4px 24px 0 #00fff022, 0 0 0 2px #232946;
  overflow: hidden;
  width: 320px;
  min-height: 320px;
  transition: transform 0.3s, box-shadow 0.3s, border 0.3s;
  cursor: pointer;
  border: 2px solid transparent;
  position: relative;
  backdrop-filter: blur(1.5px);
}

.game-card-adv:hover {
  transform: translateY(-12px) scale(1.045);
  box-shadow: 0 8px 40px 0 #00fff088, 0 0 0 2.5px #00fff0;
  border: 2px solid #00fff0;
}

.game-img-wrap {
  position: relative;
  width: 100%;
  height: 170px;
  overflow: hidden;
  border-radius: 18px 18px 0 0;
}

.game-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #b0b3b8;
  font-size: 1.2rem;
}

.game-info-adv {
  padding: 24px 20px 20px 20px;
}

.game-info-adv h3 {
  color: #00fff0;
  font-size: 1.35rem;
  margin-bottom: 12px;
  text-shadow: 0 2px 12px #00fff033;
}

.game-desc {
  color: #b0b3b8;
  font-size: 1.08rem;
  line-height: 1.6;
}

.game-meta {
  margin-bottom: 12px;
}

.game-meta span {
  color: #b0b3b8;
  font-size: 1rem;
  margin-right: 16px;
}

.game-pricing {
  margin-bottom: 12px;
}

.game-price {
  color: #00fff0;
  font-size: 1.2rem;
}

.game-price.strike {
  text-decoration: line-through;
  color: #888;
  opacity: 0.7;
  margin-right: 8px;
}

.game-discount {
  color: #00fff0;
  font-size: 1rem;
  margin-left: 8px;
}

.game-status {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  background: #00fff0;
  color: #181a20;
  font-size: 0.8rem;
}

.game-status.status-onshelf {
  background: #00fff0;
}

.game-status.status-pending {
  background: #ff0000;
}

.game-empty {
  text-align: center;
  margin: 24px 0;
  color: #00fff0;
}

.game-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 18px;
  gap: 12px;
  font-size: 1rem;
}

.game-pagination button {
  min-width: 36px;
  height: 36px;
  padding: 0 16px;
  border: 1.5px solid #00fff0;
  border-radius: 18px;
  background: transparent;
  color: #00fff0;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s, border 0.18s;
  box-shadow: 0 0 0 #00fff0;
  outline: none;
  position: relative;
  z-index: 1;
}

.game-pagination button:hover:not(:disabled) {
  background: linear-gradient(90deg, #00fff0 0%, #232946 100%);
  color: #181a20;
  box-shadow: 0 0 8px #00fff0;
  border: 1.5px solid #00fff0;
}

.game-pagination button:disabled {
  color: #888;
  border: 1.5px solid #444;
  background: #232946;
  cursor: not-allowed;
  box-shadow: none;
}

.game-pagination span {
  color: #b0b3b8;
  font-size: 1rem;
  margin: 0 6px;
  letter-spacing: 1px;
}

.star-rating {
  display: inline-flex;
  vertical-align: middle;
  margin-right: 8px;
}

.star {
  width: 22px;
  height: 22px;
  fill: #00fff0;
  stroke: #00fff0;
  stroke-width: 0.5;
  margin-right: 2px;
  filter: drop-shadow(0 0 6px #00fff055);
  transition: fill 0.2s;
}

.star.empty {
  fill: #232946;
  stroke: #00fff0;
  filter: none;
}

.rating-num {
  color: #00fff0;
  font-size: 1.08rem;
  font-weight: bold;
  margin-left: 2px;
  vertical-align: middle;
}

.game-detail-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}
.modal-bg-blur {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-size: cover;
  background-position: center;
  filter: blur(32px) brightness(0.5);
  z-index: 1;
}
.modal-content {
  background: linear-gradient(135deg, #232946 60%, #4e8cff22 100%);
  border-radius: 32px;
  box-shadow: 0 16px 64px #4e8cff55, 0 0 0 3px #4e8cff44;
  padding: 0 0 40px 0;
  min-width: 800px;
  max-width: 900px;
  min-height: 600px;
  max-height: 96vh;
  color: #e0e6f0;
  position: relative;
  text-align: left;
  animation: modalPop 0.3s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}
.detail-list {
  list-style: none;
  padding: 0;
  margin: 0 0 28px 0;
  font-size: 1.18rem;
  width: 100%;
  max-width: 800px;
  line-height: 2.1;
}
.detail-list li {
  margin-bottom: 10px;
}
.comment-section {
  margin-top: 32px;
  background: #232946cc;
  border-radius: 16px;
  padding: 24px 24px;
  box-shadow: 0 4px 24px #4e8cff22;
  width: 100%;
  max-width: 800px;
}
.comment-section h3 {
  color: #4e8cff;
  margin-bottom: 12px;
}
.comment-list {
  min-height: 40px;
}
.comment-placeholder {
  color: #aaa;
  font-size: 1rem;
  text-align: center;
  padding: 12px 0;
}
.comment-input-bar {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}
.comment-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1.5px solid #4e8cff;
  background: #181a20;
  color: #e0e6f0;
  font-size: 1rem;
}
.comment-submit-btn {
  background: linear-gradient(90deg, #4e8cff 0%, #6ed0ff 100%);
  color: #232946;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 1px 6px #4e8cff22;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.comment-submit-btn:hover {
  background: linear-gradient(90deg, #6ed0ff 0%, #4e8cff 100%);
  color: #fff;
  box-shadow: 0 4px 16px #4e8cff55;
  transform: scale(1.05);
}
.close-btn {
  background: linear-gradient(90deg, #4e8cff 0%, #6ed0ff 100%);
  color: #232946;
  border: none;
  border-radius: 12px;
  padding: 12px 38px;
  font-size: 1.18rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 12px #4e8cff22;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.close-btn:hover {
  background: linear-gradient(90deg, #6ed0ff 0%, #4e8cff 100%);
  color: #fff;
  box-shadow: 0 4px 16px #4e8cff55;
  transform: scale(1.05);
}
.scrollable-modal {
  max-height: 92vh;
  overflow-y: auto;
  width: 100%;
}
.modal-img {
  width: 100%;
  max-width: 1000px;
  height: 560px;
  min-height: 400px;
  max-height: 560px;
  aspect-ratio: 16/9;
  display: block;
  margin: 0 auto 36px auto;
  border-radius: 18px;
  box-shadow: 0 6px 40px #4e8cff33;
  object-fit: cover;
  background: #232946;
}
.star-row {
  display: flex;
  align-items: center;
}
.star-rating {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
}
.star {
  width: 22px;
  height: 22px;
  margin-right: 2px;
  fill: #4e8cff;
  stroke: #232946;
  stroke-width: 1.2;
}
.star.empty {
  fill: #232946;
  stroke: #4e8cff;
}
.rating-num {
  margin-left: 6px;
  color: #4e8cff;
  font-weight: bold;
  font-size: 1.1rem;
}
.pro-modal {
  position: relative;
  z-index: 2;
  padding: 48px 56px 40px 56px;
  min-width: 800px;
  max-width: 1200px;
  min-height: 600px;
  max-height: 96vh;
  background: rgba(35,41,70,0.98);
  border-radius: 32px;
  box-shadow: 0 16px 64px #4e8cff55, 0 0 0 3px #4e8cff44;
}
.modal-main-row {
  display: flex;
  flex-direction: row;
  gap: 48px;
  align-items: flex-start;
  margin-bottom: 32px;
}
.pro-img {
  width: 480px;
  height: 320px;
  min-width: 320px;
  max-width: 520px;
  min-height: 200px;
  max-height: 360px;
  aspect-ratio: 3/2;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: 0 4px 32px #4e8cff33;
  background: #232946;
}
.modal-info-card {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border-radius: 18px;
  box-shadow: 0 2px 16px #4e8cff22;
  padding: 32px 32px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 320px;
}
.pro-title {
  font-size: 2.2rem;
  font-weight: 700;
  color: #4e8cff;
  margin-bottom: 8px;
  letter-spacing: 2px;
}
.pro-price-rating {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 8px;
}
.pro-price {
  font-size: 1.6rem;
  color: #ffb300;
  font-weight: bold;
}
.pro-discount {
  font-size: 1.2rem;
  color: #ff4e4e;
  font-weight: bold;
  margin-left: 8px;
  text-decoration: line-through;
}
.pro-star {
  margin-left: 12px;
}
.pro-meta-row {
  display: flex;
  gap: 24px;
  color: #a3b8d8;
  font-size: 1.08rem;
}
.pro-config-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  color: #b0b3b8;
  font-size: 1.05rem;
}
.pro-devices {
  color: #6ed0ff;
  font-size: 1.05rem;
}
.pro-desc {
  margin-top: 8px;
  color: #e0e6f0;
  font-size: 1.12rem;
  line-height: 1.8;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  padding: 12px 16px;
}
.pro-comment {
  margin: 0 auto 0 auto;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  padding: 0 32px 32px 32px;
  width: 100%;
  max-width: 800px;
  min-width: 320px;
  align-self: auto;
}
.modal-img-top-bar {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 0;
}
.modal-img-top {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 0;
  box-shadow: none;
  background: #232946;
}
.modal-content-topimg {
  margin-top: 0;
  border-radius: 0 0 24px 24px;
}
.modal-info-card {
  width: 100%;
  max-width: 800px;
  min-width: 320px;
  box-sizing: border-box;
  margin: 0 auto 0 auto;
  padding: 32px 32px 24px 32px;
}
.modal-img-inner-top-bar {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 0;
}
.modal-img-inner-top {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 32px 32px 0 0;
  box-shadow: 0 4px 32px #4e8cff33;
  background: #232946;
}
.divider-line {
  width: 100%;
  height: 1.5px;
  background: linear-gradient(90deg, #4e8cff33 0%, #23294644 100%);
  margin: 0 0 24px 0;
  border-radius: 1px;
}
.modal-btn-row {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-top: 36px;
}
.buy-btn {
  background: linear-gradient(90deg, #4e8cff 0%, #6ed0ff 100%);
  color: #232946;
  border: none;
  border-radius: 12px;
  padding: 12px 38px;
  font-size: 1.18rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 12px #4e8cff22;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.buy-btn:hover {
  background: linear-gradient(90deg, #6ed0ff 0%, #4e8cff 100%);
  color: #fff;
  box-shadow: 0 4px 16px #4e8cff55;
  transform: scale(1.05);
}
.comment-item {
  border-bottom: 1px solid #2a2d3a;
  padding: 12px 0 8px 0;
}
.comment-header {
  display: flex;
  justify-content: space-between;
  color: #7fa7d6;
  font-size: 0.98rem;
  margin-bottom: 4px;
}
.comment-nick {
  font-weight: bold;
}
.comment-time {
  font-size: 0.92rem;
  color: #b0b3b8;
}
.comment-content {
  color: #e0e6f0;
  font-size: 1.08rem;
  line-height: 1.6;
  word-break: break-all;
}
.comment-more-row {
  text-align: center;
  margin: 12px 0 0 0;
}
.comment-more-btn {
  background: linear-gradient(90deg, #4e8cff 0%, #6ed0ff 100%);
  color: #232946;
  border: none;
  border-radius: 8px;
  padding: 8px 24px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 1px 6px #4e8cff22;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.comment-more-btn:hover {
  background: linear-gradient(90deg, #6ed0ff 0%, #4e8cff 100%);
  color: #fff;
  box-shadow: 0 4px 16px #4e8cff55;
  transform: scale(1.05);
}
</style>

<style>
html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  background: #181a20;
  box-sizing: border-box;
}
</style>